#include "GrappleObject.h"
#include "GrapplingArm.h"
#include "Player.h"
#include "GamePlayState.h"



GrappleObject::GrappleObject(GrapplingArm* grapple)
{
	gA = grapple;
	SetTag("grapple");
	objectID = "Grapple";
}


GrappleObject::~GrappleObject(void)
{
}

void GrappleObject::HandleCollision(GameObject& other, CollisionInfo& info)
{
	if(other.GetObjectID() == "Player" || other.GetTag() == "enter door" || other.GetObjectID() == "Trip Wire" || GamePlayState::GetInstance()->GetPlayer()->GetToolManager()->GetMag().GetAttched() == &other
		|| other.GetObjectID() == "Machine" || other.GetObjectID() == "Generator")
	{
	}
	else /*if (!(gA->GetAttached()))*/
	{
		if(other.GetObjectID() == "Static Object")
		{
			if(other.CanBeGrappled())
			{
				if( gA->GetDirection() == Right )
				{
					if(info.Side == RIGHT)
						gA->SetAttached(&other);
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Up )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SetAttached(&other);
				}
				else if( gA->GetDirection() == Left )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SetAttached(&other);
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Down )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
 						gA->SetAttached(&other);
					else if(info.Side == TOP)
						gA->SideCollide();
				}
			}
			else
			{
				if( gA->GetDirection() == Right )
				{
					if(info.Side == RIGHT)
						gA->CollideNoAttach();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Up )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->CollideNoAttach();
				}
				else if( gA->GetDirection() == Left )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->CollideNoAttach();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Down )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->CollideNoAttach();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
			}

		}
		else
		{
			if(other.CanBeGrappled())
			{
				if( gA->GetDirection() == Right )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SetAttached(&other);
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Up )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SetAttached(&other);
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Left )
				{
					if(info.Side == RIGHT)
						gA->SetAttached(&other);
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Down )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SetAttached(&other);
				}
			}
			else
			{
				if( gA->GetDirection() == Right )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->CollideNoAttach();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Up )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->CollideNoAttach();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Left )
				{
					if(info.Side == RIGHT)
						gA->CollideNoAttach();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->SideCollide();
				}
				else if( gA->GetDirection() == Down )
				{
					if(info.Side == RIGHT)
						gA->SideCollide();
					else if(info.Side == LEFT)
						gA->SideCollide();
					else if(info.Side == BOTTOM)
						gA->SideCollide();
					else if(info.Side == TOP)
						gA->CollideNoAttach();
				}
			}
		}

	}
}
